// releasePage/pages/addOperator/chooseChannel/deleteChannel/deleteChannel.js
const app = getApp();
Page({
    /**
     * 页面的初始数据
     */
    data: {
        type: '', //type  00--LTE频段  01--NR频段
        deleteId: '',
        selectId: '',
        deleteName: '',
        deleteNum: 0,
        sceneContent: [],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            deleteId: options.id,
            deleteName: options.name,
            deleteNum: options.num,
            type: options.type,
        });
        this.getNetDeviceList();
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    //选择网路场景
    chooseScene(e) {
        let _that = this;
        console.log(e.currentTarget.dataset.id);
        _that.setData({
            selectId: e.currentTarget.dataset.id,
        });
    },
    // 确认
    submitBtn(e) {
        let _that = this;
        if (!_that.data.selectId) return;
        wx.showModal({
            title: '提示',
            content: `是否确认分配（共${_that.data.deleteNum}个数据）?`,
            success: function (res) {
                if (res.confirm) {
                    wx.request({
                        url:
                            app.globalData.rootPath +
                            `cjMap/transOneNdfToAnother?authId=${app.globalData.authId}&current=${_that.data.deleteId}&target=${_that.data.selectId}&type=${_that.data.type}`,
                        method: 'GET',
                        header: {
                            'content-type': 'application/json',
                        },
                        success: function (res) {
                            console.log(res);
                            let pages = getCurrentPages();
                            let prevPage = pages[pages.length - 2]; //上一页面
                            let prevPage3 = pages[pages.length - 3];
                            let prevPage4 = pages[pages.length - 4];
                            prevPage.getNetDeviceList();
                            try {
                                prevPage3.getCityOperatorDetail();
                            } catch (err) {
                                prevPage3.refresh();
                            }
                            if (
                                prevPage4 &&
                                typeof prevPage4.refresh == 'function'
                            ) {
                                try {
                                    prevPage4.refresh('operator');
                                } catch (err) {
                                    prevPage4.refresh();
                                }
                            }
                            setTimeout(function () {
                                wx.navigateBack({
                                    delta: 1, // 返回上一级页面。
                                });
                            }, 300);
                        },
                    });
                } else {
                    console.log('点击取消回调');
                }
            },
        });
    },
    // 获取频段号列表
    getNetDeviceList() {
        let _that = this;
        wx.request({
            url:
                app.globalData.rootPath +
                `cjMap/getNetFrequencyChannelList?authId=${app.globalData.authId}&type=${_that.data.type}&createtimeorder=asc`,
            method: 'GET',
            header: {
                'content-type': 'application/json',
            },
            success: function (res) {
                console.log(res);
                _that.setData({
                    sceneContent: res.data.data,
                });
            },
        });
    },
});
